package middleware

import (
	"github.com/gin-gonic/contrib/cors"
	"github.com/gin-gonic/gin"
)

func CORS() gin.HandlerFunc {
	return cors.Default()
	/*return cors.New(cors.Config{
		//准许跨域请求网站,多个使用,分开
		//AllowedOrigins:     []string{"*"},
		//all origins are allowed. AllowOriginFunc or AllowedOrigins is not needed
		AllowAllOrigins:  true,
		AllowedMethods:   []string{"PUT", "PATCH", "POST", "GET", "DELETE"},
		AllowedHeaders:   []string{"Content-Type,AccessToken,X-CSRF-Token, Authorization, Token"},
		ExposedHeaders:   []string{"Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type"},
		AllowCredentials: true,
		//AllowOriginFunc: func(origin string) bool {
		//	return true
		//},
		MaxAge: 12 * time.Hour,
	})
	*/
	/*
		c.Header("Access-Control-Allow-Origin", "*")
		c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token")
		c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
		c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
		c.Header("Access-Control-Allow-Credentials", "true")

		//放行所有OPTIONS方法
		if method == "OPTIONS" {
			c.AbortWithStatus(http.StatusNoContent)
		}
	*/

}
